<?php


namespace App\Services\Algo;

use App\Interf\Calculable;
use TestingItemService;
use App\Models\LogHelper;

class ZAMentalAlgo extends BaseTestingAlgo implements Calculable
{
    public $allAnswers;
    private $typeFourExpress;

    public function __construct($tid, $answerStr, $typeFourExpress = null)
    {
        parent::__construct($tid, $answerStr);
        $this->typeFourExpress = $typeFourExpress;
        $this->allAnswers = $this->convertAllAnswers();
    }


    public function calculate()
    {
        return $this->entrance($this->tid, $this->answers);
    }

    /**
     * 将拼装后的答案转换成字符串
     * @return string
     */

    public function resultToStr()
    {
        return $this->arrToStr($this->answers);
    }

    /**
     * @param $tid
     * @param $answers
     * @return float|null
     */
    protected function entrance($tid, $answers)
    {
        $answer = $this->getAnswerObjByIndex(31);
        $totalScore = $answer['weight'];
        return $totalScore;
    }

    protected function convertAllAnswers()
    {
        if ($this->typeFourExpress) {
            $result = $this->fourTypeArray($this->typeFourExpress, $this->answers);

            foreach ($result as $v) {
                $this->answers[] = $v;
            }
        }

        return $this->answers;
    }


}